package com.agy.filemanager.controller;

import com.agy.filemanager.common.TreeUtil;
import com.agy.filemanager.entity.DcBaseSinopecOrg;
import com.agy.filemanager.entity.TreeModel;
import com.agy.filemanager.service.DcSystemSinpecOrgService;
import com.agy.filemanager.toolClass.Result;
import com.agy.filemanager.toolClass.ResultUtil;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 中石化组织机构
 */
@RestController
@RequestMapping("/SystemSinopecOrg")
public class SystemSinopecOrgController {
    @Autowired
    private DcSystemSinpecOrgService dcSystemSinpecOrgService;

    /**
     * 查询组织机构树
     * @return
     */
    @PostMapping("/selectTree")
    public Result selectTree(){
        List<TreeModel>  treeList = this.dcSystemSinpecOrgService.selectTree();
        //List<TreeModel> treeList = TreeUtil.getTree(this.dcSystemSinpecOrgService.selectTree());
        return ResultUtil.success(treeList);
    }

    /**
     * 根据父级编码查询
     * @param request
     * @return
     */
    @PostMapping("/selectGrid")
    public Map<String,Object> selectGrid(HttpServletRequest request){
        int pageSize =Integer.parseInt(request.getParameter("pageSize"));
        int pageNum =Integer.parseInt(request.getParameter("pageNum"));
        String parentCode = request.getParameter("parentCode");
        String orgname = request.getParameter("orgname");
        Page list = this.dcSystemSinpecOrgService.selectGrid(pageNum,pageSize,parentCode,orgname);
        Map<String,Object> map=new HashMap<>();
        map.put("total",list.getTotal());
        map.put("rows",list.getResult());
        return map;
    }

    /**
     * 根据id查询子节点
     * @return
     */
    @GetMapping("/childTreeNodes")
    public List<TreeModel> childTreeNodes(String id){
       return this.dcSystemSinpecOrgService.childTreeNodes(id);
    }
}
